package com.lin.filegraph.utils.parser.node;

import org.eclipse.jdt.core.dom.ASTNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 10:21
 */

public class JMethodNode extends JTreeNode {

    private String methodName = null;
    private String qualifiedName = null;
    private String methodSignature = null;
    private String modifier = null;
    private String returnType = null;
    private MethodClassification methodClassification = null;
    List<JMethodInvocationNode> listMethodInvokeNode = new ArrayList<JMethodInvocationNode>();
    private boolean isAPI = false;
    private boolean hasComment = false;
    private int callDepth = 0;
    private int callDepthInComp = 0;
    private List<String> listOfQuoteTypes = null;

    public JMethodNode(String filePath, ASTNode astNode, String methodName, String qualifiedName, String methodSignature,
                       String modifier, String returnType, MethodClassification methodClassification, boolean isAPI,
                       boolean hasComment) {
        super(filePath, astNode);
        this.methodName = methodName;
        this.qualifiedName = qualifiedName;
        this.methodSignature = methodSignature;
        this.modifier = modifier;
        this.returnType = returnType;
        this.methodClassification = methodClassification;
        this.isAPI = isAPI;
        this.hasComment = hasComment;
    }


    public String getMethodName() {
        return methodName;
    }


    public String getMethodSignature() {
        return methodSignature;
    }

    public String getModifier() {
        return modifier;
    }

    public String getReturnType() {
        return returnType;
    }

    public MethodClassification getMethodClassification() {
        return methodClassification;
    }

    public boolean isAPI() {
        return isAPI;
    }

    public boolean isHasComment() {
        return hasComment;
    }

    public String getQualifiedName() {
        return qualifiedName;
    }

    public List<JMethodInvocationNode> getListMethodInvokeNode() {
        return listMethodInvokeNode;
    }

    public void addMethodInvocationNode(JMethodInvocationNode node) {
        listMethodInvokeNode.add(node);
    }

    public JTypeNode getFatherType() {
        JTreeNode fatherNode = super.getFatherNode();
        if (fatherNode instanceof JTypeNode) {
            return (JTypeNode) fatherNode;
        } else {
            System.err.println("ERR");
            return null;
        }
    }

    public List<JParameterNode> getAllParameters() {
        List<JParameterNode> listParameter = new ArrayList<JParameterNode>();
        List<? extends JTreeNode> tempList = super.getChildrenNodeList();
        for (JTreeNode basedNode : tempList) {
            if (basedNode instanceof JParameterNode) {
                JParameterNode parameterNode = (JParameterNode) basedNode;
                listParameter.add(parameterNode);
            }
        }
        return listParameter;
    }

    @Override
    public String toString() {
        return "[MethodNode] " + methodSignature + "  StartLine:" + getStartLine();
    }

    /**
     * @return the callDepth
     */
    public int getCallDepth() {
        return callDepth;
    }

    /**
     * @param callDepth
     *            the callDepth to set
     */
    public void setCallDepth(int callDepth) {
        this.callDepth = callDepth;
    }

    public int getCallDepthInComp() {
        return callDepthInComp;
    }

    public void setCallDepthInComp(int callDepthInComp) {
        this.callDepthInComp = callDepthInComp;
    }

    /**
     * @return the listOfQuoteTypes
     */
    public List<String> getListOfQuoteTypes() {
        return listOfQuoteTypes;
    }

    /**
     * @param listOfQuoteTypes
     *            the listOfQuoteTypes to set
     */
    public void setListOfQuoteTypes(List<String> listOfQuoteTypes) {
        this.listOfQuoteTypes = listOfQuoteTypes;
    }

    public enum MethodClassification {
        isConstructor, isInitializer, isCommon,
    }

}
